#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

/**
 * Definition for singly-linked list.
 */
struct ListNode {
	int val;
	struct ListNode* next;
};
typedef struct ListNode listNode, *listnode;

struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2);

int main()
{
	return 0;
}

struct ListNode* mergeTwoLists(struct ListNode* l1, struct ListNode* l2)
{
	listNode p1_aux = { 0, l1 },
			 p2_aux = { 0, l2 };
	listnode p1 = &p1_aux, p2 = &p2_aux;
	while (p1->next && p2->next) {
		int sub = p1->next->val - p2->next->val;
		if (sub > 0) {
			listnode temp = p2->next;
			p2->next = p2->next->next;
			temp->next = p1->next;
			p1->next = temp;
		} else if (sub <= 0) {
			p1 = p1->next;
		}
	}

	if (p2->next) p1->next = p2->next;

	return p1_aux.next;
}
